<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>根据已知节点查找其他节点</title>
    <style>
        .selected{
            background: red;
        }
    </style>
    <script>
        function f1(){
            let i3 = document.getElementById("i3");
            // 节点名.className = "class选择器的名字"
            // 表示为指定的节点赋予指定的class选择器样式
            i3.className = "selected";
        }
        function f2(){
            let i3 = document.getElementById("i3");
            let i2 = i3.previousSibling.previousSibling;
            i2.className = "selected";
        }

        function f3(){
            let i3 = document.getElementById("i3");
            let i4 = i3.nextSibling.nextSibling;
            i4.className = "selected";
        }

        function fn(obj){
            obj.className = "selected";
        }
    </script>
</head>
<body>
<ul>
    <li>item1</li>
    <li>item2</li>
    <li id="i3">item3</li>
    <li>item4</li>
    <li>item5</li>
</ul>

<button onclick="fn(i3)">当前节点</button>
<button onclick="fn(i3.previousSibling.previousSibling)">上一个节点</button>
<button onclick="fn(i3.nextSibling.nextSibling)">下一个节点</button>
<button onclick="fn(i3.parentNode)">父节点</button>
<button onclick="fn(i3.parentNode.firstChild.nextSibling)">第一个节点</button>
<button onclick="fn(i3.parentNode.lastChild.previousSibling)">最后一个节点</button>
<script>
    let i3 = document.getElementById("i3");
</script>
</body>
</html>